﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//委托的多播
namespace SeniorMultiDelegate
{
    internal class Program
    {
        public delegate int CaculateDelegate(int x, int y);
        static void Main(string[] args)
        {
            CaculateDelegate cal0 = new CaculateDelegate(Add);
            CaculateDelegate cal1 = new CaculateDelegate(Multiply);
            CaculateDelegate cal2 = new CaculateDelegate(Add); 
            CaculateDelegate caculateDelegate = null;
            caculateDelegate += cal0;
            caculateDelegate += cal1;
            caculateDelegate += cal2;
            Console.WriteLine(caculateDelegate(4,5));
            //获取委托列表
            Delegate[] delegates = caculateDelegate.GetInvocationList();

            foreach (CaculateDelegate d in delegates)
            {
                int result = d(5, 5);
                Console.WriteLine(result);
            }

        }

       public static int Multiply(int a, int b)
        {
            return a * b;
        }

        public static int Add(int a, int b)
        {  
            return a + b; 
        }  

    }
}
